package com.example.last.controller;

import com.example.last.common.Result;
import com.example.last.entity.Admin;
import com.example.last.entity.Doctor;
import com.example.last.entity.Params;
import com.example.last.service.DoctorService;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@CrossOrigin
@RequestMapping("/doctor")
@RestController
public class DoctorController {
    @Resource
    private DoctorService doctorService;
    
    @GetMapping("/search")
    public Result findBySearch(@Param("params") Params params){
        PageInfo<Doctor> info = doctorService.findBySearch(params);
        return Result.success(info);
    }

    @GetMapping("/username/{username}")
    public Result findByName(@PathVariable String username){
        Doctor doctor = doctorService.findByName(username);
        return Result.success(doctor);
    }

    //新增信息
    @PostMapping
    public Result save(@RequestBody Doctor doctor){
        if(doctor.getId() == null){
            doctorService.add(doctor);
        }else{
            doctorService.update(doctor);
        }
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        doctorService.delete(id);
        return Result.success();
    }


}
